<%@ page import="com.wuming.house.security.SecurityHander" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/3/20
  Time: 18:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>管理户型</title>
    <link rel="stylesheet" href="${allServerPath}static/layui/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${allServerPath}static/layui/css/public.css" media="all"/>
</head>
<body style="background-color: #f0f2f5;" class="childrenBody">
<div class="layui-fluid wuli-main">
    <div class="layui-row">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>编辑户型</legend>
        </fieldset>
        <form class="layui-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 100px">户型名称</label>

                    <div class="layui-input-inline">
                        <input type="text" id="layoutName" name="layoutName" autocomplete="off"
                               class="layui-input" value="${layout['layoutName']}" placeholder="示例:二居">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 100px">户型详细名称</label>

                    <div class="layui-input-inline">
                        <input type="text" id="layoutDetail" name="layoutDetail" autocomplete="off"
                               class="layui-input" value="${layout['layoutDetail']}" placeholder="示例:两室一厅">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 100px">户型面积</label>

                    <div class="layui-input-inline">
                        <input type="text" id="layoutArea" name="layoutArea" autocomplete="off"
                               class="layui-input" value="${layout['layoutArea']}" placeholder="示例:120">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 100px">图片</label>

                    <div class="layui-upload-list" style="display: inline">
                        <img class="layui-upload-img" id="uploadImage" style="width: 150px;height: 100px">
                        <p id="demoText"></p>
                    </div>


                </div>
            </div>
            <input type="hidden" name="id" value="${layout['id']}">
            <input type="hidden" name="picUrl" value="${layout['picUrl']}">
        </form>
        <div class="layui-row wuli-button">
            <button type="button" class="layui-btn" id="btnUploadImg">选择图片</button>
            <button class="layui-btn layui-btn-normal" name="btnSave">保存户型</button>
        </div>
    </div>
</div>
<script type="text/javascript" src="${allServerPath}static/layui/layui/layui.js"></script>
<script src="${allServerPath}static/js/jquery-2.1.4.min.js"></script>
<script>
    layui.use(['layer', 'form', 'jquery', 'upload'], function () {
        var form = layui.form
            , layer = layui.layer
            , $ = layui.$
            , upload = layui.upload;

        var id = $("input[name='id']").val();
        var picUrl = $("input[name='picUrl']").val();
        if (id != null && id != "") {
            $("#uploadImage").attr("src", ${banner.picUrl});
        }

        //普通图片上传
        var picId = null;
        upload.render({
            elem: '#btnUploadImg'
            , url: '${allServerPath}web/houselayout/uploadImg.htmls'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#uploadImage').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                if (res.success) {
                    picId = res.data;
                }
                //上传成功
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });

        $("button[name='btnSave']").on('click', function () {
            $.ajax({
                type: "post",
                data: {
                    id: id,
                    houseId: '${houseId}',
                    layoutName: $("#layoutName").val(),
                    picId: picId,
                    picUrl: picUrl,
                    layoutArea: $("#layoutArea").val(),
                    layoutDetail: $("#layoutDetail").val()
                },
                url: '${allServerPath}web/houselayout/save.htmls',
                success: function (obj) {
                    if (obj.success) {
                        layer.msg("保存成功");
                    }
                }
            });
        });
    });


    <%--function setBannerImg() {--%>
    <%--$.ajax({--%>
    <%--type: "post",--%>
    <%--data: {--%>
    <%--id: '${banner.picId}',--%>
    <%--},--%>
    <%--url: '${allServerPath}web/goodsCate/getGoodImage.htmls?t=<%=System.currentTimeMillis()%>',--%>
    <%--success: function (obj) {--%>
    <%--if (obj.success) {--%>
    <%--$("#uploadImage").attr("src", obj.data);--%>
    <%--}--%>
    <%--}--%>
    <%--});--%>
    <%--}--%>
</script>
</body>
</html>
